
package model;

import java.util.Date;

public class RMC {

	private static final double CONVERSIO = 0.5144; //1 nudo = 0,5144 m/s
	private Temps time;
	private String status;
	private float speed;
	private float angle;
	private Date date;
	private String checksum;
	private Coordenada longitude;
	private Coordenada magVar;
	private Coordenada latitude;

	public RMC() {
		super();
		time = new Temps();
		date = new Date(); 
	}

	public RMC(Temps time, String status, float speed, float angle, Date date,
			String checksum, Coordenada longitude, Coordenada magVar,
			Coordenada latitude) {
		super();
		this.time = time;
		this.status = status;
		this.speed = (float) (speed*CONVERSIO);
		this.angle = angle;
		this.date = date;
		this.checksum = checksum;
		this.longitude = longitude;
		this.magVar = magVar;
		this.latitude = latitude;
	}

	/**
	 * 
	 * @return time
	 */
	public Temps getTime() {
		return time;
	}

	/**
	 * 
	 * @param time
	 */
	public void setTime(String time) {
		Temps aux = new Temps();
		aux.setHores(Integer.parseInt(time.charAt(0) + "") * 10
				+ Integer.parseInt(time.charAt(1) + ""));
		aux.setMinuts(Integer.parseInt(time.charAt(2) + "") * 10
				+ Integer.parseInt(time.charAt(3) + ""));
		aux.setSegons(Integer.parseInt(time.charAt(4) + "") * 10
				+ Integer.parseInt(time.charAt(5) + ""));
		aux.setCentesimes(Integer.parseInt(time.charAt(7) + "")
				* 100
				+ (Integer.parseInt(time.charAt(8) + "") * 10 + Integer
						.parseInt(time.charAt(9) + "")));
		this.time = aux;
	}

	/**
	 * 
	 * @return status
	 */
	public String getStatus() {
		return status;
	}
	
	/**
	 * 
	 * @param status
	 */
	public void setStatus(String status) {
		this.status = status;
	}
	
	/**
	 * 
	 * @return speed
	 */
	public float getSpeed() {
		return speed;
	}
	
	/**
	 * 
	 * @param speed
	 */
	public void setSpeed(float speed) {
		this.speed = speed;
	}
	
	/**
	 * 
	 * @return angle
	 */
	public float getAngle() {
		return angle;
	}
	
	/**
	 * 
	 * @param angle
	 */
	public void setAngle(float angle) {
		this.angle = angle;
	}
	
	/**
	 * 
	 * @return date
	 */
	public Date getDate() {
		return date;
	}
	/**
	 * 
	 * @param date
	 */
	@SuppressWarnings("deprecation")
	public void setDate(String date) {
		this.date.setDate(Integer.parseInt(date));
	}
	
	/**
	 * 
	 * @return checksum
	 */
	public String getChecksum() {
		return checksum;
	}
	
	/**
	 * 
	 * @param checksum
	 */
	public void setChecksum(String checksum) {
		this.checksum = checksum;
	}
	
	/**
	 * 
	 * @return longitude
	 */
	public Coordenada getLongitude() {
		return longitude;
	}
	
	/**
	 * 
	 * @param longitude
	 */
	public void setLongitude(Coordenada longitude) {
		this.longitude = longitude;
	}
	
	/**
	 * 
	 * @return magVar
	 */
	public Coordenada getMagVar() {
		return magVar;
	}
	
	/**
	 * 
	 * @param magVar
	 */
	public void setMagVar(Coordenada magVar) {
		this.magVar = magVar;
	}
	
	/**
	 * 
	 * @return latitude
	 */
	public Coordenada getLatitude() {
		return latitude;
	}
	
	/**
	 * 
	 * @param latitude
	 */
	public void setLatitude(Coordenada latitude) {
		this.latitude = latitude;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + Float.floatToIntBits(angle);
		result = prime * result
				+ ((checksum == null) ? 0 : checksum.hashCode());
		result = prime * result + ((date == null) ? 0 : date.hashCode());
		result = prime * result
				+ ((latitude == null) ? 0 : latitude.hashCode());
		result = prime * result
				+ ((longitude == null) ? 0 : longitude.hashCode());
		result = prime * result + ((magVar == null) ? 0 : magVar.hashCode());
		result = prime * result + Float.floatToIntBits(speed);
		result = prime * result + ((status == null) ? 0 : status.hashCode());
		result = prime * result + ((time == null) ? 0 : time.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		RMC other = (RMC) obj;
		if (Float.floatToIntBits(angle) != Float.floatToIntBits(other.angle))
			return false;
		if (checksum == null) {
			if (other.checksum != null)
				return false;
		} else if (!checksum.equals(other.checksum))
			return false;
		if (date == null) {
			if (other.date != null)
				return false;
		} else if (!date.equals(other.date))
			return false;
		if (latitude == null) {
			if (other.latitude != null)
				return false;
		} else if (!latitude.equals(other.latitude))
			return false;
		if (longitude == null) {
			if (other.longitude != null)
				return false;
		} else if (!longitude.equals(other.longitude))
			return false;
		if (magVar == null) {
			if (other.magVar != null)
				return false;
		} else if (!magVar.equals(other.magVar))
			return false;
		if (Float.floatToIntBits(speed) != Float.floatToIntBits(other.speed))
			return false;
		if (status == null) {
			if (other.status != null)
				return false;
		} else if (!status.equals(other.status))
			return false;
		if (time == null) {
			if (other.time != null)
				return false;
		} else if (!time.equals(other.time))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "RMC [time=" + time + ", status=" + status + ", speed=" + speed
				+ ", angle=" + angle + ", date=" + date + ", checksum="
				+ checksum + ", longitude=" + longitude + ", magVar=" + magVar
				+ ", latitude=" + latitude + "]";
	}



}
